﻿' ----------------------------------------------------------------------------------
' Microsoft Developer & Platform Evangelism
' 
' Copyright (c) Microsoft Corporation. All rights reserved.
' 
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
' OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ----------------------------------------------------------------------------------
' The example companies, organizations, products, domain names,
' e-mail addresses, logos, people, places, and events depicted
' herein are fictitious.  No association with any real company,
' organization, product, domain name, email address, logo, person,
' places, or events is intended or should be inferred.
' ----------------------------------------------------------------------------------

Imports System.Net

Namespace Credentials
    Friend NotInheritable Class HttpUtility

        Private Sub New()
        End Sub

        Public Shared Function ParseQueryString(ByVal queryString As String) As WebHeaderCollection
            Dim res = New WebHeaderCollection()
            Dim num As Integer = If(queryString IsNot Nothing, queryString.Length, 0)
            For i As Integer = 0 To num - 1
                Dim startIndex As Integer = i
                Dim num4 As Integer = -1
                Do While i < num
                    Dim ch As Char = queryString.Chars(i)
                    If ch = "="c Then
                        If num4 < 0 Then
                            num4 = i
                        End If
                    ElseIf ch = "&"c Then
                        Exit Do
                    End If

                    i += 1
                Loop

                Dim str As String = Nothing
                Dim str2 As String = Nothing
                If num4 >= 0 Then
                    str = queryString.Substring(startIndex, num4 - startIndex)
                    str2 = queryString.Substring(num4 + 1, (i - num4) - 1)
                Else
                    str2 = queryString.Substring(startIndex, i - startIndex)
                End If

                res(str.Replace("?", String.Empty)) = System.Net.HttpUtility.UrlDecode(str2)
            Next i

            Return res
        End Function
    End Class
End Namespace